﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Threading;
using System.Windows.Threading;

namespace OVS_Tools
{
    public static class UIThreadHelper
    {
        public static void UIThread(this Control control, Action code)
        {
            if (Thread.CurrentThread == Dispatcher.CurrentDispatcher.Thread)
            {
                control.Dispatcher.BeginInvoke(code);
                return;
            }
            code.Invoke();
        }

        public static void UIThreadInvoke(this Control control, Action code)
        {
            if (Thread.CurrentThread == Dispatcher.CurrentDispatcher.Thread)
            {
                control.Dispatcher.BeginInvoke(code);
                return;
            }
            code.Invoke();
        }
    }
}
